# 使用类实现迭代器，实现斐波拉契数列
# class fbnq():
#     def __iter__(self):
#         self.o = 0
#         self.t = 1
#         return self.t
#
#     def __next__(self):
#         x = self.t
#         self.o, self.t = self.t, self.t+self.o
#         return x
#     def fbnq2(self):
#         o, t, = 0, 1
#         while 1:
#             o, t = t, t+o
#             yield t



# f = fbnq()
# f.__iter__()
# print(f.__next__())
# print(f.__next__())
# print(f.__next__())
# print(f.__next__())
# print(f.__next__())

# print(next(f.fbnq2()))
# print(next(f.fbnq2()))
# print(next(f.fbnq2()))
# print(next(f.fbnq2()))
# print(next(f.fbnq2()))
# 使用面向对象做一个ATM（存取款功能）
# ATM类
# 属性：钱，区域
# 方法：存取
#     用户可以取钱
#     取了钱，ATM的钱就会减少
#     用户账户的钱也会减少
# 用户类
#  属性：用户名，密码，账户金额
# 要求：
#   菜单  登录验证
import time, sys


class ATM(object):
    ATM_money = 500000   # ATM初始化的后台金额
    def __init__(self,area):
        self.area = area # ATM的所在地
    def get_money(self, money1):
        self.ATM_money = self.ATM_money-money1
    def save_money(self, money2):
        self.ATM_money = self.ATM_money+money2

class Person(ATM):
    l1 = []      # 用户名单
    def __init__(self, usnm, passwd, p_money):
        self.p_money = p_money
        self.usnm = usnm
        self.passwd = passwd
        self.l1.append(self.usnm) # 用户定义时，自动加入名单

    def search_us(self):
        usnm1 = input("请输入您要查找的用户：")
        if usnm1 in self.l1:
            print(f"已找到用户{usnm1}")
            time.sleep(0.5)
        else:
            print("未找到相应的用户名")

    def menu(self):
        while 1:
            print("开始".center(11, "#"))
            print("1. get_money")
            print("2. save_money")
            print("3. search")
            print("4. exit")
            print("退出登录".center(11, "#"))
            option = input("请输入您的选项：")
            if option == "1":
                money1 = int(input("请输入你要取走的金额："))
                if money1 <= self.p_money:
                    self.get_money(money1)
                    self.p_money -= money1
                    print(f"您取走的金额为{money1}，您剩余的金额为{self.p_money}。")
                    time.sleep(0.5)
                    continue
                else:
                    print("您输入的金额大于您拥有的金额，请重新开始。")
            elif option == "2":
                money2 = int(input("请输入您要存取的金额："))
                self.save_money(money2)
                self.p_money += money2
                print(f"您存入的金额为{money2}，您剩余的金额为{self.p_money}.")
                time.sleep(0.5)
                continue
            elif option == "3":
                self.search_us()
            elif option == "4":
                print("程序退出")
                sys.exit(-1)
            else:
                print("您输入的选项有误，请重新输入")
                continue

    def check_login(self):
        while 1:
            username = input("请输入您的用户名:")
            passwd = int(input("请输入您的密码:"))
            if self.usnm == username and self.passwd == passwd:
                print(f"欢迎你，{username}")
                # time.sleep(1)
                self.menu()
            else:
                print("用户名或密码错误，请重新输入。")
                time.sleep(0.5)
                continue

ATM1 = ATM("changsha")
a = Person("tyh",123456,500)
a.check_login()

